using System;
using System.Collections.Generic;
using System.Text;

namespace Developex.DatabaseWrapper.Fields
{
	/// <summary>
	/// UpdatedOn field
	/// </summary>
	public class UpdatedOnField : Field<DateTime>
	{
		#region Constructors

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="name"></param>
		public UpdatedOnField(string name)
			: base(name)
		{
		}

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="name"></param>
		/// <param name="flags"></param>
		public UpdatedOnField(string name, FieldFlags flags)
			: base(name, flags)
		{
		}

		#endregion

		#region Overrides

		/// <summary>
		/// Set updated datetime
		/// </summary>
		/// <returns>true if changed</returns>
		public override bool SetUpdateAutoValue(Connection conn)
		{
			Value = conn.EventHandler.GetCurrentDateTime();
			return true;
		}

		/// <summary>
		/// Set updated=created datetime
		/// </summary>
		/// <param name="conn"></param>
		/// <returns>true if changed</returns>
		public override bool SetCreateAutoValue(Connection conn)
		{
			Value = conn.EventHandler.GetCurrentDateTime();
			return true;
		}

		///<summary>
		/// Create object 
		///</summary>
		///<returns></returns>
		/// <remarks>
		/// Here should be only object creation, all data copy should be in overrided Clone function.
		/// Used only in base version of Clone function.
		/// Should be overrided for ICloneable interface.
		/// </remarks>
		protected override Field<DateTime> CreateObjectForClone()
		{
			return new UpdatedOnField(null);
		}

		#endregion
	}
}
